package net.kazed.nextaction.task;

import net.kazed.nextaction.R;
import net.kazed.nextaction.database.Task;
import android.app.TabActivity;
import android.content.Intent;
import android.content.res.Resources;
import android.database.Cursor;
import android.net.Uri;
import android.os.Bundle;
import android.widget.TabHost;
import android.widget.TabHost.TabSpec;

public class TaskTabsViewActivity extends TabActivity {

    private TabHost tabHost;
    private TabSpec tabSpec;
    private Uri itemUri;
    private Cursor cursor;
    
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        itemUri = getIntent().getData();
        Resources resources = getResources();

        tabHost = getTabHost();
        tabHost.addTab(tabHost.newTabSpec("task")
                .setIndicator(resources.getString(R.string.task_tab_info_title))
                .setContent(new Intent(Intent.ACTION_VIEW, itemUri, this, TaskViewActivity.class)));
        tabSpec = tabHost.newTabSpec("subTasks")
                .setIndicator(resources.getString(R.string.task_tab_sub_title))
                .setContent(new Intent(Intent.ACTION_VIEW, itemUri, this, TaskSubTasksViewActivity.class));
        tabHost.addTab(tabSpec);
        
        cursor = managedQuery(itemUri, Task.FULL_PROJECTION.getFieldNames(), null, null, null);
    }

    @Override
    protected void onResume() {
        super.onResume();
        if (cursor != null) {
            cursor.moveToFirst();
            Task task = new Task(cursor);
            setTitle(task.getDescription());
            Resources resources = getResources();
            tabSpec.setIndicator(resources.getString(R.string.task_tab_sub_title) + " (" + task.getNumberOfSubTasks() + ")");
        }
    }

}
